package com.adun.scheduler.common;

import com.adun.scheduler.common.enums.ResponseEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class AmisResult<T> {
    
    private Integer status;
    
    private String msg;
    
    private T data;
    
    private String token;
    
    private String traceId ;
    public boolean isSuccess(){
        if (ResponseEnum.SUCCESS.getCode().equals(this.status)) {
            return true;
        }
        return false;
    }
    public static <T> AmisResult<T> success(T data){
        AmisResult<T> amisResult = success();
        amisResult.setData(data);
        return amisResult;
    }

    public static <T> AmisResult<T> success(T data,String msg){
        AmisResult<T> amisResult = success();
        amisResult.setData(data);
        amisResult.setMsg(msg);
        return amisResult;
    }

    public static <T> AmisResult<T> success(){
        AmisResult<T> amisResult = new AmisResult<>();
        amisResult.setStatus(ResponseEnum.SUCCESS.getCode());
        amisResult.setMsg(ResponseEnum.SUCCESS.getDescription());
        return amisResult;
    }


    public static <T> AmisResult<T> success(T data, ResponseEnum responseEnum){
        AmisResult<T> amisResult = new AmisResult<>();
        amisResult.setStatus(ResponseEnum.SUCCESS.getCode());
        amisResult.setData(data);
        amisResult.setMsg(responseEnum.getDescription());
        return amisResult;
    }

    public static <T> AmisResult<T> successMsg(String msg){
        AmisResult<T> amisResult = new AmisResult<>();
        amisResult.setStatus(ResponseEnum.SUCCESS.getCode());
        amisResult.setMsg(msg);
        return amisResult;
    }


    public static <T> AmisResult<T> fail( String msg) {
        return fail(ResponseEnum.FAIL.getCode(), msg,null);
    }
    public static <T> AmisResult<T> fail(Integer code, String msg) {
        return fail(code, msg,null);
    }
    public static <T> AmisResult<T> fail(Integer code, String msg, T data) {
        return new AmisResult<>(code, msg, data, null,null);
    }


}
